package com.stylefeng.guns.modular.system.controller;

import com.stylefeng.guns.common.annotion.log.BussinessLog;
import com.stylefeng.guns.common.constant.Dict;
import com.stylefeng.guns.common.controller.BaseController;
import com.stylefeng.guns.common.persistence.dao.OrgUserMapper;
import com.stylefeng.guns.common.persistence.model.OpUser;
import com.stylefeng.guns.common.persistence.model.OrgUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;

/**
 * 消息通知表控制器
 *
 * @author fengshuonan
 * @Date 2018-12-28 09:24:53
 */
@Controller
@RequestMapping("/orgUser")
public class OrgUserController extends BaseController {

    private String PREFIX = "/system/orgUser/";
    @Autowired
    OrgUserMapper orgUserMapper;

    /**
     * 跳转到消息通知表首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "orgUser.html";
    }

    /**
     * 跳转到添加消息通知表
     */
    @RequestMapping("/orgUser_add")
    public String orgUserAdd() {
        return PREFIX + "orgUser_add.html";
    }

    /**
     * 跳转到修改消息通知表
     */
    @RequestMapping("/orgUser_update/{orgUserId}")
    public String orgUserUpdate(@PathVariable Integer orgUserId, Model model) {
        OrgUser old = orgUserMapper.selectById(orgUserId);
        model.addAttribute("orgUser",old);
        return PREFIX + "orgUser_edit.html";
    }

    /**
     * 获取消息通知表列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        List<OrgUser> opUsers = orgUserMapper.selectList(null);
        return opUsers;
    }

    /**
     * 新增消息通知表
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add() {
        return super.SUCCESS_TIP;
    }

    /**
     * 删除消息通知表
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    @BussinessLog(value = "删除节点",key = "orgUserId",dict = Dict.DeleteDict)
    public Object delete(@RequestParam Integer orgUserId) {
        this.orgUserMapper.deleteById(orgUserId);
        return SUCCESS_TIP;
    }


    /**
     * 修改消息通知表
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(OrgUser orgUser) {
        Integer update = orgUserMapper.updateById(orgUser);
        return super.SUCCESS_TIP;
    }

    /**
     * 消息通知表详情
     */
    @RequestMapping(value = "/detail")
    @ResponseBody
    public Object detail() {
        return null;
    }
}
